package us.wili.dev.model.validator.valid;

import us.wili.dev.jwt.model.ChannelEnum;
import us.wili.dev.model.validator.annotation.LoginChannel;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 核对登录渠道的枚举
 * @author wkx
 * @date 2018/9/18 10:56
 */
public class LoginChannelValidator implements ConstraintValidator<LoginChannel, Integer> {

    @Override
    public void initialize(LoginChannel constraintAnnotation) {

    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (value == null) {
            return false;
        }
        for (ChannelEnum channelEnum : ChannelEnum.values()) {
            if (value.equals(channelEnum.getCode())) {
                return true;
            }
        }
        return false;
    }
}
